/*
 * @Author: dingyuwen ding_yuwen@163.com
 * @Date: 2023-02-08 16:28:13
 * @LastEditTime: 2023-10-18 16:27:48
 * @LastEditors: DingYuwen 43669762+DingYuwen@users.noreply.github.com
 * @Description:
 */
import { useMemo } from 'react';
import { InvokeAIUI, PartialAppConfig } from '@tourfly/invoke';

import useUser from './useUser';

import AigcHeader from '@/common/components/header/AigcHeader';
import { getToken } from '@/common/utils';
import { useAppSelector } from '@/store/hooks';
const Invoke = () => {
  const { token } = useAppSelector((state) => state.user);
  const localToken = getToken();

  const config: PartialAppConfig = useMemo(
    () => ({
      disabledTabs: ['nodes', 'modelManager', 'batch'],
    }),
    []
  );

  const { userInfo, handleLogout } = useUser();

  setTimeout(() => {
    if (location.search && location.search.indexOf('redirect=https://aigc.aigctour.com/jinghua/aigc') > -1) {
      window.location.href = 'https://aigc.aigctour.com/jinghua/aigc'
    }
  }, 600)
  return (
    <InvokeAIUI
      baseUrl={import.meta.env.VITE_APP_BASE_URL}
      socketBase={import.meta.env.VITE_APP_SOCKET_BASE}
      token={token ?? localToken}
      config={config}
      headerComponent={<AigcHeader user={userInfo} logoutFn={handleLogout} />}
    />
  );
};

export default Invoke;
